package com.tanhua.dubbo.server.service;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.common.mapper.AdminMapper;
import com.tanhua.common.pojo.Admin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * Created with IntelliJ IDEA.
 *
 * @ClassName: UserService
 * @Author:王晨晗
 * @Description: 与sso单点登录系统进行token校验功能
 * @Date: 2021/12/28/18:27
 */
@Service
public class AdminService {
    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private AdminMapper adminMapper;

    /**
     * @description  请求token解析
     * @param token
     * @updateTime 2021/12/28 23:43
     * @return: com.tanhua.common.pojo.User
     */
    public Admin queryToken(String token) {
        //发送get请求,请求sso的token校验服务,返回user对象
        try {
            //捕获sso系统请求异常,更好的知道了token是解析失败
            Admin admin = restTemplate.getForObject("http://127.0.0.1/users/" + token, Admin.class);
            return admin;
        } catch (Exception ex) {
            return null;
        }
    }

    //根据id获取user信息
    public Admin queryAdminById(Integer uid){
        QueryWrapper<Admin> wrapper = new QueryWrapper<>();
        wrapper.eq("uid",uid);
        return adminMapper.selectOne(wrapper);
    }
}
